Lecture 1
Any changes to the schedule will be communicated by the instructor through the Ariel portal.
Ariel Portal: A section dedicated to the course is available where you can find announcements, study support materials, R scripts, and more.
Course Website: https://myariel.unimi.it/course/view.php?id=2950
Email Communication: All communication with instructors should be done through students’ institutional email.
To present R programming features for data science and statistical applications
R is an integrated set of software resources for data manipulation, computation, and graphical visualization.
R is a dialect of S, developed by John Chambers and colleagues at Bell Labs starting in 1976. In 1988, it was completely rewritten in C. John Chambers once stated:
We wanted users to be able to start in an interactive environment where they weren’t aware they were programming. As their needs became clearer and their skill level increased, there should be a smooth transition toward programming, where the language and system aspects would become more relevant.
R is free and open source, which guarantees the following:
The R system is conceptually divided into two parts:
Functionality is divided into packages (collections of functions, data, and compiled code in a well-defined format).
The base system contains the packages with essential functions.
Some of the packages included in the base system are: utils, stats, datasets, graphics, grDevices, grid, methods, tools, parallel, compiler, splines, tcltk, stats4.
RStudio is an Integrated Development Environment (IDE) for R programming. You can download and install it from http://www.rstudio.com/download. It is updated once or twice a year.
To understand computations in R, two guiding principles are useful:
— John Chambers
It’s essential to know how to use help functions in R:
help.start(): Opens the help system in HTML format.help(mean): Provides help for the specific function?mean: An alternative way to get help for meanhelp("for"): Retrieves help on reserved words and special characters (e.g., TRUE, FALSE, NA)help.search("mean"): Searches for the string “mean” throughout the documentation.??mean: Another way to search for “mean” in the documentation.?help: Provides details on how to use the help system.If you find that even after reading the help documentation you still don’t understand how to use a particular function or command, here’s what you can do:
By doing this, you increase the likelihood of getting useful support and solutions from the community.
getwd(): Retrieves the current working directory.setwd(): Changes the working directory.
setwd("c:/CorsoR")ls(): Lists the objects present in the workspace.rm(): Deletes one or more specified objects from the workspace.rm(list=ls()): Removes all objects from the workspace. DANGEROUS COMMAND!library(): Lists the installed packages in the library specified by .libPaths().install.packages("package_name"): Installs a package from CRAN.library(package_name): Loads a package into the R session..libPaths().# to indicate a comment. You can use CTRL + Shift + C in RStudio to comment or uncomment a block of code.<− is the symbol for assignment in R. When using RStudio, you can use the shortcut Alt + - to insert this assignment operator.
“There are only two hard things in Computer Science: cache invalidation and naming things.”
— Phil Karlton
When deciding on names in R, follow these basic guidelines:
_) or hyphens (-) to separate words in an object name (e.g., model_one).For more details, refer to the Tidyverse Style Guide.
Not all words can be used as object names in R. There are reserved words, such as for, while, and if, which are predefined commands and cannot be renamed.
To view the complete list of reserved words, you can type the command:
+ : Addition− : Subtraction* : Multiplication/ : Division^ : Exponentiation%% : Integer division (remainder)TRUE or FALSE):> : Greater than< : Less than>= : Greater than or equal to<= : Less than or equal to== : Equal to!= : Not equal to! : NOT& : AND (element-wise)| : OR (element-wise)log(x) : Natural logarithm of xfactorial(x) : Factorial of xsqrt(x) : Square root of xsin(x) : Sine of x (in radians)cos(x) : Cosine of x (in radians)tan(x) : Tangent of x (in radians)character: Represents text or strings.numeric: Represents numbers and is divided into:
double: Double-precision floating-point numbers.integer: Integer numbers.complex: Represents complex numbers with real and imaginary parts.logical: Represents Boolean values (TRUE or FALSE).To find out how an object is stored, you can use the function typeof().